local skel = fk.CreateSkill {
  name = "peng_skill",
}

skel:addEffect("cardskill", {
  prompt = "#peng_skill",
  target_num = 1,
  mod_target_filter = function (self, player, to_select, selected, card, extra_data)
    return to_select ~= player and (to_select:getNextAlive() == player or player:getNextAlive() == to_select)
  end,
  target_filter = function(self, player, to_select, selected, _, card, extra_data)
    if not Util.CardTargetFilter(self, player, to_select, selected, _, card, extra_data) then return end
    return self:modTargetFilter(player, to_select, selected, card, extra_data) and
      (
        #selected > 0 or
        player.phase ~= Player.Play or
        (extra_data and extra_data.bypass_times) or
        self:withinTimesLimit(player, Player.HistoryPhase, card, card.trueName, to_select)
      )
  end,
  max_phase_use_time = 1,
  on_effect = function(self, room, effect)
    local to = effect.to
    if to.dead then return end
    if not to:isNude() and not effect:isDisresponsive(to) then
      local cards = room:askToCards(to, {
        min_num = 1, max_num = 1, include_equip = true, skill_name = self.name, cancelable = true, prompt = "#peng_skill-card"
      })
      if #cards > 0 then
        room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true)
        local put = room:getSubcardsByRule(effect.card, {Card.Processing})
        if #put > 0 then
          room:moveCardTo(put, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true)
        end
        return
      end
    end
    room:loseHp(to, 1, self.name)
  end,
  can_use = function(self, player, card, extra_data)
    if player:prohibitUse(card) then return end
    return (extra_data and extra_data.bypass_times) or player.phase ~= Player.Play or
      table.find(Fk:currentRoom().alive_players, function(p)
        return self:targetFilter(player, p, {}, {}, card, extra_data)
      end)
  end,
})

Fk:loadTranslationTable{
  ["peng_skill"] = "嘭！",
  ["#peng_skill"] = "令一个邻家选择将1牌置于牌堆顶或失去1体力",
  ["#peng_skill-card"] = "请将一张牌与此【嘭！】置于牌堆顶，否则失去1点体力",
}

return skel
